/**
 * Created by asus on 2017/9/25.
 */
public class MyList<T> {
    private static  int FirstRoom = 20;
    private T [] num=(T [])new  Object [FirstRoom];
    private int thesize;

    public static void setFirstRoom(int firstRoom) {
        FirstRoom = firstRoom;
    }

    public int getThesize() {
        return thesize;
    }

    public static int getFirstRoom() {
        return FirstRoom;
    }

    public void setlist(){
        thesize=0;
    }
    //ArrayList中的add(E e):将指定的元素添加到此列表的尾部。
    public boolean add(T t){
        add(thesize,t);
        return true;

    }
    public void add(int index,T t){
        if (index<0){
            System.out.println("Wrong number");
        }
        if (index>thesize){
            //ruguo

        }
        if (index == thesize){
            num[index] = t;
        }
        else if(index<thesize){
            for (int i = thesize;i>index;i--){
                num[i] =num [i-1];
            }
            num[index] = t;
        }
        thesize++;
    }
    //删除表中的元素 ArrayList remove(Object o)
    public boolean remove(T t){
        int position = -1;
        for (int i=0;i<thesize;i++){
            if (num[i]==t){
                position = i;
                break;
            }
        }
        if (position==-1){
            System.out.println("Wrong position");
            return false;
        }
        else {
            for (int i= position;i<thesize-1;i++){
               num[i] = num[i+1];
            }
            thesize --;
            return true;
        }
    }
    public T get(int index){
        T item = num[index];
        return item;

    }

    public boolean isEmpty(){
        if (thesize==0){
            return true;
        }
        else return false;

    }

    public static void main(String[] args) {
        MyList<Integer> myList = new MyList<>();

        myList.add(0);
        myList.add(3);
        myList.add(2);
        System.out.println(myList.get(1));
        myList.remove(2);

    }


}
